package mason.dp.observerjdk;

import java.util.Observable;
import java.util.Observer;

import mason.dp.observer.DisplayElement;
/**
 * 实现java.util.Observer接口来创建观察者类
 * @author MasonAir
 *
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {
	Observable observable;
	private float temperature;
	private float humidity;
	
	public CurrentConditionsDisplay(Observable o) {
		this.observable = o;
		o.addObserver(this);
	}
	
	@Override
	public void display() {
		System.out.println("当前的天气状况为（ 温度："+temperature+"  湿度：%"+humidity+")");
	}

	@Override
	public void update(Observable o, Object arg) {
		if(o instanceof WeatherData) {
			WeatherData wd = (WeatherData) o;
			this.temperature = wd.getTemperature();
			this.humidity = wd.getHumidity();
			display();
		}
	}

}
